<?php


namespace app\api\validate;


use app\lib\exception\BaseException;
use app\lib\exception\ParameterException;
use think\Exception;
use think\Request;
use think\Validate;

class BaseValidate extends Validate
{
    public function goCheck() {
        //获取http传入的参数
        //对这些参数进行校验
        $request = Request::instance();
        $params = $request->param();
        $result = $this -> batch() -> check($params);
        if (!$result) {
            $e = new ParameterException([
                'msg' => $this->error
            ]);
//            $e->msg = $this -> error;
            throw $e;
//            $error = $this -> error;
//            throw new BaseException($error);
        } else {
            return true;
        }
    }

    //自定义验证规则
    protected function isInterger($value, $rule = '', $data = '', $filed = '') {
        if (is_numeric($value) && is_int($value + 0) && ($value + 0) > 0) {
            return true;
        } else {
            return false;
        }
    }
}